﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Thep
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        #region Database
        OleDbConnection conn;
        OleDbCommand cmd;

        public void Connect()
        {
            string connectstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\\Database.a;Persist Security Info=False";
            conn = new OleDbConnection(connectstring);
            cmd = conn.CreateCommand();
        }
        #endregion

        public void ShowForm(Form Frm)
        {
            try
            {
                if (this.MdiChildren.Count() != 0)
                {
                    foreach (var child in this.MdiChildren)
                    {
                        if (Frm.Name == child.Name)
                        {
                            child.Activate();
                            
                            return;
                        }
                    }
                    Frm.MdiParent = this;
                    Frm.Show();

                }
                else
                {
                    Frm.MdiParent = this;
                    Frm.Show();
                }

            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            
            ShowForm(new FrmLoaiThepCot());
            ShowForm(new FrmDacTrungVatLieu());
            ShowForm(new FrmThongSoLienKet());
            ShowForm(new FrmHeSoAnToan());
            ShowForm(new FrmKetQua());
            ShowForm(new FrmLoaiThepCot());
            Form2 frm = new Form2();
            frm.ShowDialog();
        }

        private void btnHeSoAnToan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FrmHeSoAnToan frm = new FrmHeSoAnToan();
            ShowForm(frm);
        }

        private void btnThongSoLienKet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FrmThongSoLienKet frm = new FrmThongSoLienKet();
            ShowForm(frm);
        }

        private void btnDacTrungVatLieu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FrmDacTrungVatLieu frm = new FrmDacTrungVatLieu();
            ShowForm(frm);
        }

        private void btnDoBenVaCung_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FrmKetQua frm = new FrmKetQua();
            ShowForm(frm);
        }

        private void btnLoaiThepCot_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FrmLoaiThepCot frm = new FrmLoaiThepCot();
            ShowForm(frm);
        }

        private void menuGioiThieu_Click(object sender, EventArgs e)
        {
            Form2 f = new Form2();
            f.ShowDialog();
        }

    }
}
